

var apiHost = wx.getStorageSync("apiHost"); //请求地址
var Appid = wx.getStorageSync('Appid');
var Secret = wx.getStorageSync('Secret');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    firstCategory:'',
    firstCategoryId : '',
    SecondCate : '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getFirstCategory();

  },

  /**
   * 一级分类
   */
  getFirstCategory :function(){
    var that = this;
    wx.request({
      url: apiHost + "/mobile/goods/categorys", //仅为示例，并非真实的接口地址
      data: {
        'type': 'yh',
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var code = res.data.code;
        var msg = res.data.msg;
        if (code == "10000") {
          that.setData({
            firstCategory: res.data.data,
            firstCategoryId: res.data.data[0].codeid
          })
          that.getSecondCate(res.data.data[0].codeid);
        } else {
          that.showMsg(msg);
        }
      }
    })
  },

  /**
   * 左侧分类点击事件
   */
  categoryFri :function(e){
    var that = this;
    var cateId = e.currentTarget.dataset.cateid;
    that.setData({
      firstCategoryId: cateId
    })
    that.getSecondCate(cateId);
  },

  /**
   * 获取二级分类
   */
  getSecondCate:function(id){
    var that = this;
    wx.request({
      url: apiHost + "/mobile/goods/subCategorys", //仅为示例，并非真实的接口地址
      data: {
        id: id,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var code = res.data.code;
        var msg = res.data.msg;
        if (code == "10000") {
          console.log(res.data.data)
          that.setData({
            SecondCate: res.data.data
          })
        } else {
          that.showMsg(msg);
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },

  /**
   * 跳转到友惠
   */
  goYh :function(e){
    var codeid = e.currentTarget.dataset.codeid
    this.goPage('../activityTopic/yhj/yhj?codeid=' + codeid)
  },

  /***
   * 页面跳转
  */
  searchInput:function(e){
    var value = e.detail.value;
    this.goPage('../goods/searchgoods/searchgoods?value=' + value)
  },
  /**
* 跳转页面
*/
  goPage: function (url) {
    wx.showLoading({
      title: '跳转中',
      icon: 'loading',
      mask: true
    })
    wx.navigateTo({
      url: url,
      success: function () {
        wx.hideLoading();
      }
    })
  }
})